package cn.javaxxw.springboot.service.impl;

import cn.javaxxw.springboot.dto.PageRequest;
import cn.javaxxw.springboot.entity.User;
import cn.javaxxw.springboot.mapper.UserMapper;
import cn.javaxxw.springboot.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 功能描述: 
 * @author  TuYong
 * @date  2022/9/14 14:17
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService  {

    @Override
    public IPage<User> queryPage(PageRequest request) {
        IPage<User> page = new Page<>(request.getPageNum(),request.getPageSize());
        QueryWrapper<User> queryWrapper =new QueryWrapper<>();
        if("asc".equals(request.getOrder())){
            queryWrapper.orderByAsc(StringUtils.isNotEmpty(request.getField()),request.getField());
        }else if("desc".equals(request.getOrder())){
            queryWrapper.orderByDesc(StringUtils.isNotEmpty(request.getField()),request.getField());
        }
        return  baseMapper.selectPage(page,queryWrapper);
    }
}
